using System;
using System.Drawing;
using System.Windows.Forms;
using TXLooker.WorkItemExtention.Core;

namespace TXLooker.WorkItemExtention.UI.OLViewExtension
{

    partial class PanelContainer : UserControl
    {
        private UserControl _control;

        public PanelContainer()
        {
            InitializeComponent();
        }

        
        // Attach nested panel control
        public void AttachControl(UserControl control)
        {
            this.pnlContainer.Controls.Add(control);
            _control = control;
            _control.Size = pnlContainer.Size;
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            using (Pen pen = new Pen(OutlookThemes.BorderColor))
            {
                //Draw a border around the control, to provide Outlook-like design
                Rectangle rect = new Rectangle(this.pnlContainer.Left - 1, this.pnlContainer.Top - 1, this.pnlContainer.Width + 1, this.pnlContainer.Height + 1);
                e.Graphics.DrawRectangle(pen, rect);
            }
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            //The size has been change, invalidate the control
            if (_control != null)
                _control.Size = pnlContainer.Size;
            this.Invalidate();
        }

        private void BarControlContainer_Load(object sender, EventArgs e)
        {
            //Set the background color according to the current Outlook theme
            this.BackColor = OutlookThemes.BackgroundColor;
        }

    }
}